<?php

class DiaryListModel
{
    private $lbsModel;
    private $diaryAttachmentModel;
    private $autoUidModel;
    private $diaryListKeyPrefix =   'DL/';
    private $rewardKeyPrefix    =   'RA/';
    private $rewardtargetKeyPrefix =   'RAT/';
    private $diaryListCacheModel;
    private $topicModel;
    private $groupInfoModel;
    private $slaveKey               =   '/slave';
    private $hotDiarys = array();
    private $displayWithScore = [];
    private $voteModel;
    
    public function __construct(){
        $this->diaryAttachmentModel =   new DiaryAttachmentModel();
        $this->autoUidModel         =   new AutoUidModel();
        $this->diaryListCacheModel  =   new DiaryListCacheModel();
        $this->topicModel           =   new TopicModel();
        $this->groupInfoModel       =   new GroupInfoModel();
        $this->lbsModel             =   new LbsModel();
		$this->voteModel            =   new VoteModel();
        $this->displayWithScore = [
            10000000000 => 1,
            10000000001 => 2,
            10000000002 => 3
        ];
    }    
    
    public function addDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM001';
            return  FALSE;
        }
        $data['uid']    =   $diaryInfo['uid'];
        $data['bodyId'] =   $diaryInfo['bodyId'];
        $data['time']   =   AC::SERVER_TIME;
        
        isset($diaryInfo['rBodyId'])        &&  $data['rBodyId']        =   $diaryInfo['rBodyId'];
        isset($diaryInfo['rUid'])           &&  $data['rUid']           =   $diaryInfo['rUid'];
        isset($diaryInfo['saveTime'])       &&  $data['time']           =   $diaryInfo['saveTime'];
        isset($diaryInfo['title'])          &&  $data['title']          =   $diaryInfo['title'];
        isset($diaryInfo['content'])        &&  $data['abbreviation']   =   UK::getstr($diaryInfo['content'], 500, '...');
        isset($diaryInfo['secret'])         &&  $data['secret']         =   $diaryInfo['secret'];
        isset($diaryInfo['attachment'][0])  &&  $data['attachmentPath'] =   $diaryInfo['attachment'][0];
        isset($diaryInfo['voice'][0])       &&  $data['attachmentPath'] =   $diaryInfo['voice'][0]['path'];
        isset($diaryInfo['video'][0])       &&  $data['attachmentPath'] =   $diaryInfo['video'][0]['path'];
		isset($diaryInfo['link'][0])        &&  $data['attachmentPath'] =   $diaryInfo['link'][0]['path'];
        $data['label']          =   (isset($diaryInfo['label']) && intval($diaryInfo['label']) > 0 && intval($diaryInfo['label']) <  AC::DIARY_TAG_MAXID) ? intval($diaryInfo['label']) : 0;
        isset($diaryInfo['topics'])	        &&	$data['topics']	        =   strval($diaryInfo['topics']);
        isset($diaryInfo['extras'])	        &&	$data['extras']		    =   $diaryInfo['extras'];
        isset($diaryInfo['geo'])            &&  $data['geo']            =   empty($diaryInfo['geo']) ? '' : UK::JsonFormat($diaryInfo['geo']);
        isset($diaryInfo['diaryType'])      &&  $data['inReview']       =   $diaryInfo['diaryType'];
	isset($diaryInfo['vote'])           &&  $data['vote']           =    $diaryInfo['vote'];

        $key    =   $this->diaryListKeyPrefix. $data['uid'];		
        $result =   Storage::addData($key, $data);

        if (empty($result))
        {
            AC::$errorNo    =   'DLM002';
            return  FALSE;
        }

        return  $result;
    }

	public function updateDiaryList($diaryInfo)
	{
		if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
		{
			AC::$errorNo    =   'DLM001';
			return  FALSE;
		}
		$data['uid']    =   $diaryInfo['uid'];
		$data['bodyId'] =   $diaryInfo['bodyId'];

		isset($diaryInfo['rBodyId'])        &&  $data['rBodyId']        =   $diaryInfo['rBodyId'];
		isset($diaryInfo['rUid'])           &&  $data['rUid']           =   $diaryInfo['rUid'];
		isset($diaryInfo['saveTime'])       &&  $data['time']           =   $diaryInfo['saveTime'];
		isset($diaryInfo['title'])          &&  $data['title']          =   $diaryInfo['title'];
		isset($diaryInfo['content'])        &&  $data['abbreviation']   =   UK::getstr($diaryInfo['content'], 500, '...');
		isset($diaryInfo['secret'])         &&  $data['secret']         =   $diaryInfo['secret'];
		isset($diaryInfo['attachment'][0])  &&  $data['attachmentPath'] =   $diaryInfo['attachment'][0];
		isset($diaryInfo['voice'][0])       &&  $data['attachmentPath'] =   $diaryInfo['voice'][0]['path'];
		isset($diaryInfo['video'][0])       &&  $data['attachmentPath'] =   $diaryInfo['video'][0]['path'];
		isset($diaryInfo['link'][0])        &&  $data['attachmentPath'] =   $diaryInfo['link'][0]['path'];
		$data['label']          =   (isset($diaryInfo['label']) && intval($diaryInfo['label']) > 0 && intval($diaryInfo['label']) <  AC::DIARY_TAG_MAXID) ? intval($diaryInfo['label']) : 0;
		isset($diaryInfo['topics'])	        &&	$data['topics']	        =   strval($diaryInfo['topics']);
		isset($diaryInfo['extras'])	        &&	$data['extras']		    =   $diaryInfo['extras'];
		isset($diaryInfo['geo'])            &&  $data['geo']            =   empty($diaryInfo['geo']) ? '' : UK::JsonFormat($diaryInfo['geo']);
		isset($diaryInfo['diaryType'])      &&  $data['inReview']       =   $diaryInfo['diaryType'];
		isset($diaryInfo['vote'])           &&  $data['vote']           =    $diaryInfo['vote'];

		$where = array('bodyId'=>$data['bodyId']);
		$key    =   $this->diaryListKeyPrefix. $data['uid'];
		$result =   Storage::setConditionData($key, $data,$where);

		if (empty($result))
		{
			AC::$errorNo    =   'DLM002';
			return  FALSE;
		}

		return  $result;
	}

    public function getDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
        $secret =   0;
        if (!empty($diaryInfo['secret']))   $secret =   1;

        $where  =   ' secret = '. $secret.' AND status = 0 ';
        if (!empty($diaryInfo['id']))   $where  =   ' id > '. $diaryInfo['id']. ' AND secret = '. $secret.' AND status = 0 ';

        $start  =   isset($diaryInfo['start'])  ?   $diaryInfo['start'] :   0;
        $length =   isset($diaryInfo['length']) ?   $diaryInfo['length']:   AC::DIARY_LIST_DEFAULT_LEN;
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $orderBy=   ' id DESC ';
        if ($start  <   0)  $start  =   0;

        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    
    public function getLastestDiary ($uid, $start = 0, $length = 1) {
        if (empty($uid)){
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
    
        $where = NULL;
        $key    =   $this->diaryListKeyPrefix. $uid .$this->slaveKey;
        $orderBy=   ' id DESC ';
    
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }
    
    public function getAllTopicDiarys($uid)/*{{{*/
    {
        if (empty($uid))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
    
        $where  =   " uid = ". $uid." AND extras != '' AND status = 0 ";
        $key    =   $this->diaryListKeyPrefix. $uid;
        $result =   Storage::getConditionManyData($key, $where);
        return  $result;
    }/*}}}*/
    
    public function getDiarySecretList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
        $secret =   0;
        if (!empty($diaryInfo['secret']))   $secret =   1;
    
        $where  =   ' secret = '. $secret.' AND status = 0 ';
        if (!empty($diaryInfo['id']))   $where  =   ' id < '. $diaryInfo['id']. ' AND secret = '. $secret.' AND status = 0 ';
        $diaryInfo['uid']!=AC::HOST_UID && $where .= ' AND inReview=0';
    
        $start  =    0;
        $length =   isset($diaryInfo['length']) ?   $diaryInfo['length']:   AC::DIARY_LIST_DEFAULT_LEN;
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $orderBy=   ' id DESC ';
        if ($start  <   0)  $start  =   0;
    
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    
    public function getDiaryListUp($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
        if (empty($diaryInfo['id']))    return  $this->getDiaryList($diaryInfo);
        $secret =   0;
        if (!empty($diaryInfo['secret']))   $secret =   1;

        $start  =   isset($diaryInfo['start'])  ?   $diaryInfo['start'] :   0;
        $length =   isset($diaryInfo['length']) ?   $diaryInfo['length']:   AC::DIARY_LIST_DEFAULT_LEN;
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   ' id > '. $diaryInfo['id']. ' AND secret = '. $secret.' AND status = 0 ';
        $orderBy=   ' id ASC ';
        if ($start  <   0)  $start  =   0;

        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    public function getDiaryListDown($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
        if (empty($diaryInfo['id']))    return  $this->getDiaryList($diaryInfo);
        $secret =   0;
        if (!empty($diaryInfo['secret']))   $secret =   1;

        $start  =   isset($diaryInfo['start'])  ?   $diaryInfo['start'] :   0;
        $length =   isset($diaryInfo['length']) ?   $diaryInfo['length']:   AC::DIARY_LIST_DEFAULT_LEN;
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   ' id < '. $diaryInfo['id']. ' AND secret = '. $secret.' AND status = 0 ';
        $orderBy=   ' id DESC ';
        if ($start  <   0)  $start  =   0;

        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/

    public function getDiaryListInfo($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM003';
            return  FALSE;
        }

        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId'], 'status' => 0);
        $result =   Storage::getConditionData($key, $where);
        return  $result;
    }/*}}}*/
    
    public function getDiaryListInfoByBodyId($bodyId, $type=AC::FEED_DIARY)/*{{{*/
    {
        $result =   UK::getDataByBodyid($type, $bodyId);
       
        return  $result;
    }/*}}}*/

    public function setDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM001';
            return  FALSE;
        }
        $data = array();
        $data['uid']    =   $diaryInfo['uid'];

        isset($diaryInfo['title'])          &&  $data['title']          =   $diaryInfo['title'];
//         isset($diaryInfo['content'])        &&  $data['abbreviation']   =   UK::getstr($diaryInfo['content'], 140, "...");
        isset($diaryInfo['secret'])         &&  $data['secret']         =   $diaryInfo['secret'];
        isset($diaryInfo['inReview'])       &&  $data['inReview']       =   $diaryInfo['inReview'];
        isset($diaryInfo['commentTimes'])   &&  $data['commentTimes']   =   $diaryInfo['commentTimes'];
        isset($diaryInfo['time'])  && !empty($diaryInfo['time'])  &&  $data['time']       =   $diaryInfo['time'];
        isset($diaryInfo['attachment'][0])  &&  $data['attachmentPath'] =   $diaryInfo['attachment'][0];

        $key    =   $this->diaryListKeyPrefix. $data['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId']);
        $result =   Storage::setConditionData($key, $data, $where);

        if (empty($result))
        {
            AC::$errorNo    =   'DLM006';
            return  FALSE;
        }
        return  $result;
    }/*}}}*/

    public function countTimes($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM004';
            return  FALSE;
        }

        $data   =   array();
        isset($diaryInfo['viewTimes'])      &&  $data['viewTimes']      =   1;
        isset($diaryInfo['commentTimes'])   &&  $data['commentTimes']   =   1;
        isset($diaryInfo['likeTimes'])      &&  $data['likeTimes']      =   1;
        isset($diaryInfo['shareTimes'])     &&  $data['shareTimes']     =   1;
        isset($diaryInfo['repostTimes'])    &&  $data['repostTimes']    =   1;
        if (empty($data)) {
            return  FALSE;
        }

        // 缓存更新
        $this->diaryListCacheModel->addDiaryNums($diaryInfo);
        
        if ($data['viewTimes']) {
            $this->sendRedisSyncJob($diaryInfo['bodyId']);
            return TRUE;
        }

        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId']);
        $result =   Storage::changeNumValueAdd($key, $data, $where);
        return  $result;
    }/*}}}*/
    
    private function sendRedisSyncJob ($bodyId) {
        global $_G;
        $host_name = empty($_G['serverHost']) ? "na" : $_G['serverHost'];
        $data = array(
            "task" => "diary_views",
            "bodyId"  => strval($bodyId),
            "source" => $host_name,
            "time" => AC::SERVER_TIME
        );
    
        RedisPool::doBackgroundGearmanJob("redis_sync", UK::JsonFormat($data), $bodyId);
    }

    public function countTotal($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DLM009';
            return  FALSE;
        }
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];

        $where  =   array('secret' => 0, 'status' => 0);
        if (!empty($diaryInfo['secret']))   $where  =   array('secret' => 1, 'status' => 0);
        $result =   Storage::countDataRow($key, $where);
        return  $result;
    }/*}}}*/

    public function decCountTimes($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM004';
            return  FALSE;
        }

        $data   =   array();
        isset($diaryInfo['commentTimes'])   &&  $data['commentTimes']   =   -1;
        isset($diaryInfo['likeTimes'])      &&  $data['likeTimes']      =   -1;
        isset($diaryInfo['shareTimes'])     &&  $data['shareTimes']     =   -1;
        if (empty($data))
        {
            AC::$errorNo    =   'DLM005';
            return  FALSE;
        }

        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId']);
        $result =   Storage::changeNumValueAdd($key, $data, $where);
        return  $result;
    }/*}}}*/
    
    # decCountTimes 修改了commenTimes的传参     /*{{{*/
    public function commentCountTimes($diaryInfo)
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM004';
            return  FALSE;
        }
    
        $data   =   array();
        isset($diaryInfo['commentTimes'])   &&  $data['commentTimes']   =   $diaryInfo['commentTimes'];
        isset($diaryInfo['likeTimes'])      &&  $data['likeTimes']      =   -1;
        isset($diaryInfo['shareTimes'])     &&  $data['shareTimes']     =   -1;
        if (empty($data))
        {
            AC::$errorNo    =   'DLM005';
            return  FALSE;
        }
    
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId']);
        $result =   Storage::changeNumValueAdd($key, $data, $where);
        return  $result;
    }/*}}}*/
    
    public function removeDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DLM007';
            return  FALSE;
        }

        $data   =   array('status' => 1);
        $key    =   $this->diaryListKeyPrefix. $diaryInfo['uid'];
        $where  =   array('bodyId' => $diaryInfo['bodyId']);
        $result =   Storage::setConditionData($key, $data, $where);
        if (empty($result))
        {
            AC::$errorNo    =   'DLM008';
        }
        return  $result;
    }/*}}}*/

    public function countCommentPeople($xdIndex)/*{{{*/
    {
        if (is_null($xdIndex))  return  FALSE;

        $updateSql  =   '
            UPDATE xxtDiaryKit.diaryList_'. $xdIndex. ' AS xd SET xd.commentPeople = 
            (
                SELECT num FROM xxtComment.commentPeople AS xc WHERE xc.bodyId = xd.bodyId AND xc.tableIndex='. $xdIndex. '
            )
            ';
        $keyClient  =   $this->diaryListKeyPrefix. $xdIndex;
        $result     =   Storage::execDbSentenceByClient($keyClient, $updateSql);
        return  $result;
    }/*}}}*/
    
    /**
     * 根据bodyId查找日记摘要
     * 先从缓存中读取,没有再从数据库,然后再加入缓存,并刷新改篇日记的redis计数
     * @param unknown $bodyId
     * @return Ambigous <Ambigous, boolean, string, NULL, unknown>|boolean|multitype:multitype: string NULL unknown Ambigous <string, unknown> Ambigous <boolean, unknown, multitype:>
     */
    public function getDiaryInfoByBodyId($bodyId, $uid = 0){
        if (AC::HOST_UID) $uid = AC::HOST_UID;
        if (empty($bodyId)) return array();
        
        $diaryInfo = $this->diaryListCacheModel->getDiaryCache($bodyId);
        if (!empty($diaryInfo) && intval($diaryInfo['status']) == 0 && !empty($diaryInfo['nickname']) && intval($diaryInfo['last_time']) > 0){
            // 判断最后读取时间大于一天时,更新最后读取时间
            if ((AC::SERVER_TIME - intval($diaryInfo['last_time'])) > 86400){
                $this->diaryListCacheModel->updateDiaryTime($bodyId);
            }
            $diaryInfo['is_favor'] = $this->checkIsLike($uid, $bodyId);

			if ($diaryInfo['linkList']) {
				foreach ($diaryInfo['linkList'] as &$val) {
					$val['info'] = $val['info'] ? $val['info'] : '{"title":"粉粉日记","subtitle":"粉粉日记","picture":"/9F/CF/11/Image/975D893D-6AEE-392B-54E6-584140049174.jpg"}';
				}
			}else{
				foreach ($diaryInfo['attachmentList'] as $attach){
					if($attach['attachmentType']==4 && $attach['attachmentPath'] && $attach['info']){
						$diaryInfo['linkList'][] = $attach;
					}else{
						$tmp[] = $attach;
					}
				}
				$diaryInfo['attachmentList'] = $tmp;
			}

            if ($diaryInfo['voiceList']) {
                foreach ($diaryInfo['voiceList'] as &$val) {
                    $val['info'] = $val['info'] ? $val['info'] : "0,0";
                }
            }
            if ($diaryInfo['videoList']) {
                foreach ($diaryInfo['videoList'] as &$val) {
                    $val['info'] = $val['info'] ? $val['info'] : "0,0";
                }
            }else{
                foreach ($diaryInfo['attachmentList'] as $attach){
                    if($attach['attachmentType']==3 && $attach['attachmentPath'] && $attach['info']){
                        $diaryInfo['videoList'][] = $attach;
                    }
                }
            }
            $diaryInfo['geo']=$this->filterGeoData($diaryInfo['geo']);
            return $diaryInfo;
        }
        
        $diaryInfo = $this->getDiaryListInfoByBodyId($bodyId);
        if (empty($diaryInfo) || intval($diaryInfo['status']) != 0) {
	       return NULL;
        }
        $userInfo   =   $this->autoUidModel->getUserInfo($diaryInfo['uid'],'',AC::HOST_UID);
        $diaryInfo['nickname'] =    $userInfo['nickname'];
        $diaryDetail =  $this->changeDiaryListItem($diaryInfo);

        $diaryDetail['is_favor'] = $this->checkIsLike($uid, $bodyId);

        $diaryDetail['inReview']!=1 && $this->diaryListCacheModel->addDiaryCache($bodyId, $diaryDetail);
        if ($uid) {
            $this->diaryListCacheModel->initDiaryNums($bodyId, $diaryDetail);
        }
        
        $diaryDetail['geo']=$this->filterGeoData($diaryDetail['geo']);

        return $diaryDetail;
    }
    
    public function filterGeoData($geo){
        if(empty($geo)) return array();
        $geoData    =     json_decode($geo,TRUE);     
       
        $result     =     array(
            'citycode'  => md5($geoData['province'].$geoData['city']),
            'name'      => $geoData['province'].' '.$geoData['city']
        );
       
        $citys=array('北京市','上海市','天津市','重庆市');
        
        if(in_array(trim($geoData['city']),$citys)){         
            $result     =     array(
                'citycode'  => md5($geoData['city'].$geoData['region']),
                'name'      => $geoData['city'].' '.$geoData['region']
            );          
        }
        return $result;
    }
    
    /**
     * 日记是否喜欢
     */
    public function checkIsLike($uid, $bodyId){
        if (empty($uid)) return 0;
        
    	$isLike = $this->diaryListCacheModel->checkIsLike($uid, $bodyId);
    	if ($isLike){
    		return 1;
    	}
    	return 0;
    }
    
    /**
     * 异步队列重建
     * @param $uid
     * @param $type
     * @return boolean|Ambigous <multitype:, boolean, unknown>
     */
    public function rebuildKestrelTimeline($info,$tableNum)/*{{{*/
    {
        $length =    800;
        $key    =   $this->diaryListKeyPrefix. $info[0];
        $orderBy=   ' id DESC ';
        
        if (count($info)>1){
            $in     = implode(',',$info);
        }else{
            $in     = $info[0]; 
        }
        $where  =   " secret = 0 AND uid in({$in})";
        $dbSql  =   ' SELECT * FROM  xxtDiaryKit.diaryList_'.$tableNum ." where {$where}  ORDER BY {$orderBy} limit 0,{$length} ";

        $result =   Storage::fetchDbSentence($key, $dbSql, 2);
        
        return $result;
    }/*}}}*/
    
    /**
     * 判断日记是否重复发送
     * @param unknown $diaryInfo
     * @return boolean|string
     */
    public function checkLastContent($diaryInfo){
        $ck = md5($diaryInfo['content']);
        
        if ($diaryInfo['content'] === '使用粉粉日记里的课程表扫一扫就可以复制课表了' || $diaryInfo['content'] === '我在#粉粉日记#里用手账绘制了一幅作品，小伙伴们快来围观~'
            || $diaryInfo['content'] === '我在#粉粉日记#里用手帐绘制了一幅作品，小伙伴们快来围观~' || $diaryInfo['content'] === '讨厌~我的手帐美出天际了好嘛，再不翻牌我就不理你惹~'
            || $diaryInfo['content'] === '討厭~我的手帳美出天際了好嘛，再不翻牌我就不理妳惹~'
            || $diaryInfo['content'] === '哇~ 尊贵粉粉会员现在发的这条点滴其实并没有什么别的意思，就是单纯的想要炫一下我的卡片背景，呐~右上角那个'
            || $diaryInfo['content'] === '上传视频') {
            return true;
        }
    
        $attachment = $voice = array();
        isset($diaryInfo['attachment']) && $attachment = $diaryInfo['attachment'];
        isset($diaryInfo['voice'])      && $voice      = $diaryInfo['voice'];
        isset($diaryInfo['video'])      && $video      = $diaryInfo['video'];
        if (count($attachment) > 0 && $diaryInfo['content'] === "图片日记"){
            $ck = md5($attachment[0]['path']);
        }
        if (count($voice) > 0 && $diaryInfo['content'] === "语音日记"){
            $ck = md5($voice[0]['path']);
        }
        if (count($video) > 0 && $diaryInfo['content'] === "视频点滴"){
            $ck = md5($video[0]['path']);
        }
    
        $lastCk = $this->diaryListCacheModel->getLastCheckConnent($diaryInfo['uid']);
        if($lastCk && $lastCk==$ck && (!isset($diaryInfo['zfBodyId'])))
        {
            AC::$errorNo    =   'DC110';
            return  FALSE;
        }
        return $ck;
    }
    
    /**
     * 转发时处理数据
     * @param unknown $diaryInfo
     */
    public function repeatStatitcs($diaryInfo) {
        $staticList = array();
        #判断是否是第一次转发
        if(intval($diaryInfo['repost']) == 1) {
            $release['bodyId']         =     $diaryInfo['zfBodyId'];
            $release['uid']            =     $diaryInfo['zfUid'];
            $release['repostTimes']    =     '1';
        }
        if (intval($diaryInfo['repost']) == 2){
            $staticList['bodyId']         =     $diaryInfo['zfBodyId'];
            $staticList['uid']            =     $diaryInfo['zfUid'];
            $staticList['repostTimes']    =     1;
    
            $this->countTimes($staticList);
    
            $release['bodyId']         =     $diaryInfo['zfListInfo']['rBodyId'];
            $release['uid']            =     $diaryInfo['zfListInfo']['rUid'];
            $release['repostTimes']    =     1;
        }
    
        if(!empty($release)){
            $this->countTimes($release);
        }
    }
    
    /**
     * 有转发时调用此处处理数据
     * @param unknown $diaryInfo
     * @return boolean|unknown
     */
    public function repeatDataHandle($diaryInfo) {
        $diaryInfo['uid']     =    intval($diaryInfo['uid']);
        $diaryInfo['zfBodyId']=    intval($diaryInfo['zfBodyId']);
        $diaryInfo['zfUid']   =    intval($diaryInfo['zfUid']);
        strlen($diaryInfo['content']) < 1    &&  $diaryInfo['content']    =    '转发日记';
    
        #先查找列表信息
        $repost['uid']    =    $diaryInfo['zfUid'];
        $repost['bodyId'] =    $diaryInfo['zfBodyId'];
    
        $listInfo   =   $this->getDiaryInfoByBodyId($repost['bodyId']);
        if (empty($listInfo) || $listInfo['secret'] == 1 || $listInfo['inReview']==1){
            AC::$errorNo    =   'DC011';
            return  FALSE;
        }
    
        // 查找是否转发的转发
        if (intval($listInfo['rBodyId']) > 0 && intval($listInfo['rUid']) > 0){
        $diaryInfo['rBodyId']    =    intval($listInfo['rBodyId']);
            $diaryInfo['rUid']       =    intval($listInfo['rUid']);
            $diaryInfo['repost']     =    '2';
        }else{
            $diaryInfo['rBodyId']    =    intval($diaryInfo['zfBodyId']);
            $diaryInfo['rUid']       =    intval($diaryInfo['zfUid']);
            $diaryInfo['repost']     =    '1';
        }
        $diaryInfo['zfListInfo']    =    $listInfo;
        if (isset($listInfo['extras']) && $extras = json_decode($listInfo['extras'], true)){
            unset($extras['source'], $extras['vip']['cardbg']);
            $listInfo['extras'] = json_encode($extras);
        }
        $diaryInfo['extras']     =    $listInfo['extras'];
        return $diaryInfo;
    }
    
    // 检查用户格式
    public function changeDiaryListItem($data){
    
        $diaryInfo = array();
        $diaryInfo['id']             =    strval($data['id']);
        $diaryInfo['uid']            =    strval($data['uid']);
        $diaryInfo['nickname']       =    empty($data['nickname']) ? '' : $data['nickname'];
        $diaryInfo['rBodyId']        =    empty($data['rBodyId'])  ? '' : strval($data['rBodyId']);
        $diaryInfo['rUid']           =    empty($data['rUid'])     ? '' : strval($data['rUid']);
        $diaryInfo['bodyId']         =    strval($data['bodyId']);
        $diaryInfo['title']          =    empty($data['title'])    ? '' : $data['title'];
        $diaryInfo['abbreviation']   =    $data['abbreviation'];
        $diaryInfo['secret']         =    strval($data['secret']);
        $diaryInfo['attachmentPath'] =    empty($data['attachmentPath']) ? '' : $data['attachmentPath'] ;
        $diaryInfo['attachmentList'] =    array();
        $diaryInfo['voiceList']      =    array();
        $diaryInfo['videoList']      =    array();
        $diaryInfo['time']           =    strval($data['time']);
        $diaryInfo['status']         =    strval($data['status']);
        $diaryInfo['label']          =    empty($data['label']) ? '0' : $data['label'];
        $diaryInfo['type']           =    '1';
        $diaryInfo['commentPeople']  =    strval($data['commentPeople']);
        $diaryInfo['repostTimes']    =    strval($data['repostTimes']);
        $diaryInfo['viewTimes']      =    strval($data['viewTimes']);
        $diaryInfo['commentTimes']   =    strval($data['commentTimes']);
        $diaryInfo['likeTimes']      =    strval($data['likeTimes']);
        $diaryInfo['shareTimes']     =    strval($data['shareTimes']);
        $diaryInfo['topics']         =    strval($data['topics']);
        $diaryInfo['extras']         =    $data['extras'];      
        $diaryInfo['geo']            =    empty($data['geo']) ? '' : $data['geo'];
        $diaryInfo['inReview']       =    isset($data['inReview']) ? $data['inReview'] : 0;
	$diaryInfo['vote']           =    $data['vote'];
        if (! empty($data['attachmentPath'])) {
            // 添加了语音附件
            $attachment = $this->diaryAttachmentModel->getDiaryAllAttachment($data);
            $diaryInfo['attachmentList']    =    $attachment['attachmentList'];
            $diaryInfo['voiceList']         =    $attachment['voiceList'];
            $diaryInfo['videoList']         =    $attachment['videoList'];
			$diaryInfo['linkList']         =    $attachment['linkList'];
            if ($data['attachmentPath'] == 'Array') {
                $diaryInfo['attachmentPath']  = $diaryInfo['attachmentList'][0]['attachmentPath'];
            }
            
            if ($diaryInfo['voiceList']) {
                foreach ($diaryInfo['voiceList'] as &$val) {
                    $val['info'] = $val['info'] ? $val['info'] : "0,0";
                }
            }
            if ($diaryInfo['videoList']) {
                foreach ($diaryInfo['videoList'] as &$val) {
                    $val['info'] = $val['info'] ? $val['info'] : "0,0";
                }
            }
			if ($diaryInfo['linkList']) {
				foreach ($diaryInfo['linkList'] as &$val) {
					$val['info'] = $val['info'] ? $val['info'] : '{"title":"粉粉日记","subtitle":"粉粉日记","picture":"/9F/CF/11/Image/975D893D-6AEE-392B-54E6-584140049174.jpg"}';
				}
			}
        }

        $CWservice = new CountWeightService('diary', $data['bodyId']);
        $numInfo = $CWservice->getCountWeight();
        $diaryInfo['repostTimes'] += $numInfo['n2'];

        $viewTimes = $diaryInfo['repostTimes'] + $diaryInfo['viewTimes'] + $diaryInfo['likeTimes'] + $diaryInfo['commentTimes'];
        $diaryInfo['viewTimes'] = strval($viewTimes);
        return $diaryInfo;
    }
    
    /**
     * 话题转发的结构
     * @param unknown $data
     * @return multitype:string Ambigous <string, unknown> multitype:unknown  Ambigous <>
     */
    public function structData($data){
        $result = array(
                "url_title"	    => "",
                "url_content"   => "",
                "url_image"	    => "",
                "url_action"    => "",
                "url_type_id"   => "0",
                "url_type"	    => "",
                "url_extend"	=> array(
                                    'gid'	=>	"0",
                                    'gname'	=>	"",
                                    'cover' =>	""
                                ),
                "viewTimes"     =>  1
        );
        
        // 新的分享结构
        $extra = json_decode($data['extras'],true);
        if (isset($extra['topic']) && $extra['topic']) {
            $topic = $extra['topic'][0];
            $tid   = $topic['url_type_id'];
            $type  = $topic['url_type'];
            $uid   = $topic['url_type_uid'];
            
            $topicInfo = $this->topicModel->topicAddRedis(array('tid' => $tid));
            $groupInfo = $this->groupInfoModel->groupAddRedis($topicInfo['gid']);

            isset($topicInfo['title'])         && $result['url_title']             = $topicInfo['title'];
            isset($topicInfo['abbreviation'])  && $result['url_content']           = $topicInfo['abbreviation'];
            isset($topicInfo['attachments'][0]['attachmentPath']) && $result['url_image'] = $topicInfo['attachments'][0]['attachmentPath'];
            isset($topicInfo['gid'])           && $result['url_title']             = $topicInfo['title'];
            isset($topicInfo['gid'])           && $result['url_extend']['gid']     = $topicInfo['gid'];
            isset($topicInfo['gname'])         && $result['url_extend']['gname']   = $topicInfo['gname'];
            isset($groupInfo['cover'])         && $result['url_extend']['cover']   = $groupInfo['cover'];
            isset($topicInfo['gid'])           && $result['viewTimes']             = $topicInfo['view_num'];
            $result['url_action'] = "pinksns://group/topic?tid=".$tid."&uid=".$uid."&gid=".$topicInfo['gid'];
            $result['url_type']   = "topic";
            $result['url_type_id']= $tid;
            if (empty($topicInfo)) {
                $result['url_title'] = "该话题已被删除";
            }
            if (AC::$errorNo){
                AC::$errorNo = NULL;
            }
        }else if(isset($extra['article']) && $extra['article']) {
            //分享的文章结构为保证能被json解析，后期多做了一层base64_encode,需同时兼容前后两种
            if(is_array($extra['article'][0])){
                $article = $extra['article'][0];
            }else{
                $article = json_decode(base64_decode($extra['article'][0]), true);
            }

            $result = [];
            isset($article['url_title'])    && $result['url_title']         = $article['url_title'];
            isset($article['url_image'])    && $result['url_image']         = $article['url_image'];
            isset($article['url_content'])  && $result['url_content']       = $article['url_content'];
            isset($article['url_action'])   && $result['url_action']        = $article['url_action'];
            isset($article['url_type'])     && $result['url_type']          = $article['url_type'];
            isset($article['url_type_id'])  && $result['url_type_id']       = $article['url_type_id'];
            isset($article['url_extend'])   && $result['url_extend']        = $article['url_extend'];

            if($result['url_extend']) {
                $result['url_extend']['gid'] = '0';
                $result['url_extend']['gname'] = '0';
                $result['url_extend']['original'] = '1';
            }
            $product_version=    AC::$appInfoList[1];
            $os             =    strtolower(AC::$appInfoList[2]);
            $version = array(
                'android'          =>  '5.40',
                'ios'              =>  '5.4.0',
            );
            if($check = version_compare($product_version, $version[$os],  '<=')){
                $result['url_type'] = 'web';
                $share = new ShareController();
                if(isset($article['url_type_uid'])) {
                    $author_uid = $article['url_type_uid'];
                } else {
                    $author_uid = $result['url_extend']['uid'];
                }
                $result['url_action'] = $share->articleShare(['author_uid' => $author_uid, 'aid' => $article['url_type_id']]);
            }

            if (AC::$errorNo){
                AC::$errorNo = NULL;
            }
        }else{
            if (empty(AC::$shareSupportVersion)) {
                return array();
            }
            isset($extra['web'])    &&    $assemble_data = $extra['web'][0];
            isset($extra['app'])    &&    $assemble_data = $extra['app'][0];
            
            if (!empty($assemble_data)) {
                $result = $this->url_struct_data_assemble($result, $assemble_data);
            }
            
        }
        
        if (empty($result['url_action']) || empty($result['url_title'])) {
            return array();
        }
        
        if ($result && $result['url_title'] === '粉币乐园大转盘') {
            $result['url_image']='/70/17/23/Image/2AB2E00F-711F-0447-794B-55000FC48223.jpg';
        }
    	return $result;
    }
    
    private function url_struct_data_assemble(&$result, $data) {
        $pre = AC::$cdn_url_img;
        if ($data['url_image']) {
            $url_image = substr($data['url_image'], strlen($pre)-1);
            $result['url_image']     = $url_image;
        }
        
        $result['url_type']      = 'web';
        isset($data['url_title'])     && $result['url_title']     = $data['url_title'];
        isset($data['url_content'])   && $result['url_content']   = $data['url_content'];
        isset($data['url_action'])    && $result['url_action']    = $data['url_action'];
        return $result;
    }
    
    /**
     * 重建日志详情格式
     * @param unknown $body
     * @param unknown $list
     * @param string $comment
     * @return multitype:multitype: NULL unknown Ambigous <string, unknown> string Ambigous <boolean, unknown, multitype:>
     */
    
    public function rebuildDiaryDetail($data){
        $diaryInfo = array();
        $listNums  = $this->diaryListCacheModel->getDiaryNums($data['listInfo']['bodyId']);
        
        $diaryInfo['id']             =    strval($data['bodyInfo']['id']);
        $diaryInfo['bodyId']         =    strval($data['listInfo']['bodyId']);
        $diaryInfo['uid']            =    strval($data['bodyInfo']['uid']);
        $diaryInfo['rBodyId']        =    empty($data['listInfo']['rBodyId']) ? '' : strval($data['listInfo']['rBodyId']);
        $diaryInfo['rUid']           =    empty($data['listInfo']['rUid'])    ? '' : strval($data['listInfo']['rUid']);
        $diaryInfo['title']          =    empty($data['listInfo']['title'])   ? '' : $data['listInfo']['title'];
        $diaryInfo['content']        =    $data['bodyInfo']['content'];
        $diaryInfo['category']       =    strval(abs($data['bodyInfo']['category']));
        $diaryInfo['weather']        =    strval(abs($data['bodyInfo']['weather']));
        $diaryInfo['emotion']        =    strval(abs($data['bodyInfo']['emotion']));
        $textSize = intval($data['bodyInfo']['textSize']) > AC::DIARY_TEXT_SIZE_MAXID ? AC::DIARY_TEXT_SIZE_MAXID : strval(abs($data['bodyInfo']['textSize']));
        $diaryInfo['textSize']       =    strval(abs($textSize));
        $diaryInfo['textColor']      =    strval($data['bodyInfo']['textColor']);
        $diaryInfo['theme']          =    strval(abs($data['bodyInfo']['theme']));
        $diaryInfo['viewTimes']      =    strval(abs($listNums['viewTimes']));
        $diaryInfo['commentTimes']   =    strval(abs($listNums['commentTimes']));
        $diaryInfo['likeTimes']      =    strval(abs($listNums['likeTimes']));
        $diaryInfo['shareTimes']     =    strval(abs($data['listInfo']['shareTimes']));
        $diaryInfo['commentPeople']  =    strval(abs($data['listInfo']['commentPeople']));
        $diaryInfo['repostTimes']    =    strval(abs($listNums['repostTimes']));
        $diaryInfo['secret']         =    strval(abs($data['bodyInfo']['secret']));
        $diaryInfo['attachmentList'] =    $data['attachment'];
        $diaryInfo['voiceList']      =    $data['voiceList'];
        $diaryInfo['time']           =    strval($data['bodyInfo']['saveTime']);
        $diaryInfo['status']         =    strval($data['bodyInfo']['status']);
        $diaryInfo['label']          =    empty($data['listInfo']['label']) ? '0' : strval(abs($data['listInfo']['label']));
        $diaryInfo['user']           =    $data['user'];
        $diaryInfo['geo']            =    $data['geo'];
        $diaryInfo['is_favor']       =    strval($data['listInfo']['is_favor']);
        $diaryInfo['paper_url']      =    strval($data['bodyInfo']['paper_url']);
        $diaryInfo['viewTimes']      =    strval(abs($listNums['likeTimes'] + $listNums['commentTimes'] + $listNums['viewTimes'] + $listNums['repostTimes']));
        $diaryInfo['url_struct']     =    $data['listInfo']['url_struct'];
        return $diaryInfo;
    }
    
    // 组装转发,并构造其数据格式
    public function manipulationListData ($data)
    {
        if (intval($data['rBodyId']) < 1 || intval($data['rUid']) < 1 ) {
            return (Object) array();
        }
        $repost['bodyId'] = intval($data['rBodyId']);
        $repost['uid']    = intval($data['rUid']);
        
        $result = $this->getDiaryInfoByBodyId($repost['bodyId']);
        
        if (empty($result) || $result['secret'] == 1){
           return (Object) array();
        }
        unset($result['retweeted_status']);
        
        //  将换行符替换
        $content = UK::get_text($result['abbreviation']);
        $result['videoList'] && $content = Emotion::filterTags($content, 'VIDEO');
        $result['voiceList'] && $content = Emotion::filterTags($content, 'VOICE');
        $result['linkList'] && $content = Emotion::filterTags($content, 'LINK');
        $result['attachmentList'] && $content = Emotion::filterTags($content, 'IMG');
        $result['abbreviation'] = $content;
        
        $result['user'] = $this->autoUidModel->getUserInfo($repost['uid']);
        $result['user'] = $this->autoUidModel->checkIsMe($result['user']);
        $result['user']['nickname'] = $this->autoUidModel->getRemarkName($result['user']);
        $result['nickname']    =    $result['user']['nickname'];
        // 日记转发中的转发话题结构
        $topic = array();
        if($result['extras']){
            $topic = $this->structData($result);
            if (!empty($topic) && $topic['url_type'] != 'article') {
                $result['viewTimes']      =    strval($topic['viewTimes']);
                unset($topic['viewTimes']);
            }
            
            if (AC::$retweetShareImgVersion) {
                $topic['url_image'] = AC::getProtocolUriByOS(AC::$cdn_url_img).$topic['url_image'];
            }
        }
        $result['url_struct']    =    array();
        if (!empty($topic)){
            $result['url_struct'][] = $topic;
        }
        unset($result['extras']);
        // 限制附件显示数量
        $result['attachmentList'] = array_slice($result['attachmentList'], 0, AC::$topicDiaryAttachmentLimit );
        return $result;
    }
    /**
     * 组装列表日记摘要结构
     * @param unknown $data
     * @return multitype:multitype: string >
     */
    public function buildDiaryListItem($data, $check_host_uid = TRUE){
        // 获取日记计数
        $nums = $this->diaryListCacheModel->getDiaryNums($data['bodyId']);
        
        $diaryInfo = array();
        // 去除换行
        $connent                     =    UK::get_text($data['abbreviation']);
        $diaryInfo['id']             =    strval($data['id']);
        $diaryInfo['uid']            =    strval($data['uid']);
        $diaryInfo['nickname']       =    empty($data['nickname']) ? '' : $data['nickname'];
        $diaryInfo['nickname']       =    $this->autoUidModel->getRemarkName($diaryInfo);
        $diaryInfo['rBodyId']        =    empty($data['rBodyId']) ? '' : strval($data['rBodyId']);
        $diaryInfo['rUid']           =    empty($data['rUid']) ? '' : strval($data['rUid']);
        $diaryInfo['bodyId']         =    strval($data['bodyId']);
        $diaryInfo['abbreviation']   =    UK::tipsUpgrade($data['extras'], $connent, 'topicFd');
        $diaryInfo['abbreviation']   =    Emotion::resourcesToNull($diaryInfo['abbreviation']);
        $diaryInfo['abbreviation']   =    Emotion::emotionToCharacter($diaryInfo['abbreviation']);
		$diaryInfo['title']          =    $this->getSubscriptionTitle($data);
        $diaryInfo['secret']         =    strval($data['secret']);
        $diaryInfo['attachmentPath'] =    empty($data['attachmentPath']) ? '' : $data['attachmentPath'] ;
        $diaryInfo['attachmentList'] =    array();
        $diaryInfo['voiceList']      =    array();
        $diaryInfo['videoList']      =    array();
        $diaryInfo['time']           =    strval($data['time']);
        $diaryInfo['status']         =    strval($data['status']);
        $diaryInfo['label']          =    empty($data['label']) ? '0' : $data['label'];
        $diaryInfo['type']           =    '1';
        $diaryInfo['commentPeople']  =    strval($data['commentPeople']);
        $diaryInfo['repostTimes']    =    strval($data['repostTimes']);
        $diaryInfo['viewTimes']      =    strval($data['viewTimes']);
        $diaryInfo['commentTimes']   =    strval($data['commentTimes']);
        $diaryInfo['likeTimes']      =    strval($data['likeTimes']);
        $diaryInfo['shareTimes']     =    strval($data['shareTimes']);
        // 是否喜欢
        $diaryInfo['is_favor']       =    intval($data['is_favor']) > 0 ? strval($data['is_favor']) : '0';

        //投票
		$diaryInfo['vote'] = $this->voteModel->getVoteInfo($data['bodyId'], $data['uid'], $data['vote'], AC::HOST_UID);
        // 使用静态缓存策略减少用户信息获取量
        if ($check_host_uid) {
            $diaryInfo['user'] = NULL;
            if (!empty(AC::$user[$data['uid']])){
                $diaryInfo['user']             =     AC::$user[$data['uid']];
            }
            if (empty($diaryInfo['user'])){
                $info      =    $this->autoUidModel->getUserInfo($data['uid'],'',AC::HOST_UID);
                $diaryInfo['user']    = $this->autoUidModel->checkIsMe($info);
                $diaryInfo['user']['nickname'] = $info['nickname'];
                AC::$user[$data['uid']] = $diaryInfo['user'];
            }
        }else{
            $info      =    $this->autoUidModel->getUserInfo($data['uid']);
            $diaryInfo['user']['nickname'] = $info['nickname'];
        }
        
        
        // 使用reids计数
        if (!empty($nums)){
            $diaryInfo['repostTimes']    =    $nums['repostTimes'];
            $diaryInfo['viewTimes']      =    $nums['viewTimes'];
            $diaryInfo['commentTimes']   =    $nums['commentTimes'];
            $diaryInfo['likeTimes']      =    abs($nums['likeTimes']);
            $diaryInfo['shareTimes']     =    $nums['shareTimes'];
        }
        
        if (!empty($data['attachmentList'])){
            $diaryInfo['attachmentList'] =    $data['attachmentList'];
        }
        
        if (!empty($data['voiceList'])){
            $diaryInfo['voiceList']      =    $data['voiceList'];
        }

        if (!empty($data['videoList'])){
            $diaryInfo['videoList']      =    $data['videoList'];
        }

        if (!empty($data['attachmentPath']) && (empty($diaryInfo['attachmentList']) && empty($diaryInfo['voiceList']))) {
            $attachment = $this->diaryAttachmentModel->getDiaryAllAttachment($data);
            // 添加了语音附件
            $diaryInfo['attachmentList']    =    $attachment['attachmentList'];
            $diaryInfo['voiceList']         =    $attachment['voiceList'];
            $diaryInfo['videoList']         =    $attachment['videoList'];
            if ($data['attachmentPath'] == 'Array') {
                $diaryInfo['attachmentPath']  = $diaryInfo['attachmentList'][0]['attachmentPath'];
            }
        
        }
        
        // 转发的分享结构
        $structData = array();
        if($data['extras'] && intval($data['rBodyId']) < 1 && intval($data['rUid']) < 1){
            $structData = $this->structData($data);
            if (!empty($structData)) {
                //$diaryInfo['viewTimes']      =    strval($structData['viewTimes']);
                unset($structData['viewTimes']);
            }
        }
        $diaryInfo['url_struct']    =    array();
        if (!empty($structData)){
            $diaryInfo['url_struct'][] = $structData;
        }
        
        // 查看数(查看+喜欢+转发+评论)
//        $viewTimes = $diaryInfo['repostTimes'] + $diaryInfo['viewTimes'] + $diaryInfo['commentTimes'] + $diaryInfo['likeTimes'];
//        $diaryInfo['viewTimes'] = strval($viewTimes);

        $CWservice = new CountWeightService('diary', $data['bodyId']);
        $numInfo = $CWservice->getCountWeight();
        $diaryInfo['viewTimes'] += $numInfo['n1'];
        //$diaryInfo['repostTimes'] += $numInfo['n2'];

        // 限制附件显示数量为
        $diaryInfo['attachmentList'] = array_slice($diaryInfo['attachmentList'], 0, AC::$topicDiaryAttachmentLimit );
        return $diaryInfo;
    }

    public function getSubscriptionTitle($info){
    	$title = $info['title'];
		$abbreviation = $info['abbreviation'];
		$userinfo = $this->autoUidModel->getUserInfo($info['uid']);
		if(intval($userinfo['verified']) > 0){
			if(empty($title)){
			    //订阅号不再自动补全标题
//                $title = mb_substr($abbreviation, 0, 30, 'UTF-8');
                $title = '';
			}
		}else{
			$title = '';
		}
		return $title;
	}
    
    /**
     * 获取点滴话题
     * @param unknown $topics
     * @return multitype:|multitype:Ambigous <multitype:, multitype:string >
     */
    public function getDiaryTopic ($topics) {
        if (empty($topics)) return array();
        
        $topicInfo = json_decode($topics, true);
        $topic     = $this->groupInfoModel->assembleDataOfDiaryListTopic($topicInfo);
        if(empty($topic)){
            return array();
        }
        return array($topic);
    }

    public function checkIsHotDiaryInTopic($topics, $bodyId) {
        if (empty($bodyId) || empty($topics)) return '0';

        $topicInfo = json_decode($topics, true);

        $topicHotDiary = $this->diaryListCacheModel->getTopicHotDiaryAll($topicInfo['gid']);
        return in_array($bodyId, $topicHotDiary) ? '1' : '0';
    }
    
    public function checkIsHotDiaryOfList ($bodyId) {
        if (empty($bodyId)) return '0';
    
        if (empty($this->hotDiarys)) {
            $this->hotDiarys =  $this->diaryListCacheModel->getHotDiaryListAll(0, -1);
        }
    
        return in_array($bodyId, $this->hotDiarys) ? '1' : '0';
    }
    
    public function checkIsHotDiaryOfDetail ($bodyId) {
        if (empty($bodyId)) return '0';
    
        $score = $this->diaryListCacheModel->getHotDiaryScore($bodyId);
    
        return $score ? '1' : '0';
    }

    /**
     * 检查话题点滴是否为置顶
     * @param $topic_id
     * @param $bodyId
     * @return int|enum(0, 1, 2, 3)
     */
    public function checkIsTopDiaryOfDetail ($topic_id, $bodyId) {
        if (empty($bodyId) || empty($topic_id)) return '0';
        $score = $this->diaryListCacheModel->getTopDiaryScore($topic_id, $bodyId);
        return isset($this->displayWithScore[$score]) ? strval($this->displayWithScore[$score]) : '0';
    }

    /**
     * 获取订阅号的打赏列表
     * @param $topic_id
     * @param $bodyId
     * @return int|enum(0, 1, 2, 3)
     */
    public function getRewardList($tuid, $bodyId) {
        if (empty($tuid) || empty($bodyId)) return '0';

        /*$uids = $this->diaryListCacheModel->getRewardUids($bodyId);
        if($uids){
            return $uids;
        }*/
        $key = $this->rewardtargetKeyPrefix.$tuid;
        //$where = array('type' => 0, 'typeId' => $bodyId, 'is_success' => 1);
        $where = "type = 0 and typeId = $bodyId and is_success = 1 group by uid";
        $fields = 'uid';
        $orderBy= ' update_time DESC ';
        $result =   Storage::getFieldsConditionManyData($key, $fields, $where, $orderBy);
        
        if(!$result){
            return FALSE;
        }
        $uids = [];
        foreach ($result as $key => $val) {
            foreach ($val as $k => $v) {
                $uids[] = $v;
            }
        }
        return $uids;
    }

    /**
     * 获取订阅号的打赏列表
     * @param $topic_id
     * @param $bodyId
     * @return int|enum(0, 1, 2, 3)
     */
    public function getRewardListTest($tuid, $bodyId) {
        if (empty($tuid) || empty($bodyId)) return '0';
        $key = 'DCMT/0';
        $tableName = "xxtmall_sandbox.rewardtarget_".UK::getHashId($tuid, 32);
        $sql = "select uid from {$tableName} where type = 0 and typeId = {$bodyId} and is_success = 1 group by uid order by update_time DESC";
        $result =   Storage::fetchDbSentenceByClient($key, $sql, 2);
        
        if(!$result){
            return FALSE;
        }
        $uids = [];
        foreach ($result as $key => $val) {
            foreach ($val as $k => $v) {
                $uids[] = $v;
            }
        }
        return $uids;
    }
    
}

